home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 125
/
Freelog_MarsAvril2015_No125.iso
/
Musique
/
Quod Libet
/
quodlibet-3.3.0-installer.exe
/
bin
/
quodlibet
/
util
/
string
/
splitters.pyc
(
.txt
)
< prev
Wrap
Python Compiled Bytecode
|
2014-12-31
|
3KB
|
125 lines
# Source Generated with Decompyle++
# File: in.pyc (Python 2.7)
import re
from quodlibet.util import re_escape
def split_value(s, splitters = [
'/',
'&',
',']):
"""Splits a string. The first match in 'splitters' is used as the
separator; subsequent matches are intentionally ignored."""
if not splitters:
return [
s.strip()]
values = None.split('\n')
for spl in splitters:
spl = re.compile('\\b\\s*%s\\s*\\b' % re_escape(spl), re.UNICODE)
if not filter(spl.search, values):
continue
new_values = []
for v in values:
new_values.extend([ st.strip() for st in spl.split(v) ])
return new_values
return values
def find_subtitle(title):
if isinstance(title, str):
title = title.decode('utf-8', 'replace')
for pair in [
u'[]',
u'()',
u'~~',
u'--',
u'\xe3\x80\x9c\xe3\x80\x9c',
u'\xef\xbc\x88\xef\xbc\x89']:
if pair[0] in title[:-1] and title.endswith(pair[1]):
r = len(pair[1])
l = title[0:-r].rindex(pair[0])
if l != 0:
subtitle = title[l + len(pair[0]):-r]
title = title[:l]
return (title.rstrip(), subtitle)
return (title, None)
return None
def split_title(s, splitters = [
'/',
'&',
',']):
(title, subtitle) = find_subtitle(s)
if subtitle:
return (title.strip(), split_value(subtitle, splitters))
return (None, [])
__FEATURING = [
'feat.',
'featuring',
'feat',
'ft',
'ft.',
'with',
'w/']
__ORIGINALLY = [
'originally by ',
' cover']
__FEAT_REGEX = [ re.compile(re_escape(s + ' '), re.I) for s in __FEATURING ]
__ORIG_REGEX = [ re.compile(re_escape(s), re.I) for s in __ORIGINALLY ]
def split_people(s, splitters = [
'/',
'&',
',']):
(title, subtitle) = find_subtitle(s)
if not subtitle:
parts = s.split(' ')
if len(parts) > 2:
for feat in __FEATURING:
try:
i = [ p.lower() for p in parts ].index(feat)
orig = ' '.join(parts[:i])
others = ' '.join(parts[i + 1:])
return (orig, split_value(others, splitters))
continue
except (ValueError, IndexError):
continue
return (s, [])
old = None
for regex in __FEAT_REGEX + __ORIG_REGEX:
subtitle = re.sub(regex, '', subtitle, 1)
if old != subtitle:
break
continue
values = split_value(subtitle, splitters)
return (title.strip(), values)
def split_album(s):
(name, disc) = find_subtitle(s)
if not disc:
parts = s.split(' ')
if len(parts) > 2:
lower = parts[-2].lower()
if 'disc' in lower or 'disk' in lower:
return (' '.join(parts[:-2]), parts[-1])
return (s, None)
parts = None.split()
if len(parts) == 2 and parts[0].lower() in ('disc', 'disk', 'cd', 'vol', 'vol.'):
try:
return (name, parts[1])
return (s, None)
else:
return (s, None)